<!--
 * @FilePath: index.vue
 * @@author: wjj
 * @Date: 2024-10-10 12:57:11
 * @@Description: new js file
-->
<template>
  <!-- <div class="login_container"> -->
  <div
    class="login_container"
    :style="{ backgroundImage: 'url(' + currentBackground + ')' }"
  >
    <el-row>
      <el-col :span="12" :xs="0" :sm="7">
        <!-- <el-button type="primary" plain @click="changeImage"></el-button> -->
        <div style="width: 60px; height: 60px" @click="changeImage"></div>
      </el-col>
      <el-col :span="12" :xs="24" :sm="12">
        <el-form
          class="login_form"
          :model="loginForm"
          :rules="rules"
          ref="loginForms"
          @keyup.enter="login"
        >
          <!-- <h1 style="margin-left: 40%; margin-right: 30%">Hello</h1> -->
          <h2 style="margin-left: 32%; margin-right: 30%; color: black">
            QA智能化平台欢迎您
          </h2>
          <el-form-item>
            <div class="btns1" style="margin-left: 30%">
              <el-link
                type="danger"
                :href="feishuurl"
                style="border-bottom: 2px solid #f56c6d !important"
              >
                <span style="font: 3em sans-serif">飞书👆</span>
                <!-- <el-image
                  style="width: 50px; height: 50px"
                  :src="feishuimg"
                  fit="fill"
                  class="clickable-image"
                /> -->
                <span style="font: 3em sans-serif">登陆</span>
              </el-link>
            </div>
          </el-form-item>
          <el-form-item>
            <el-tag style="margin-left: 45%" type="danger" size="Default">
              <span style="font: 1.5em sans-serif">or</span>
            </el-tag>
          </el-form-item>
          <el-form-item prop="username">
            <el-input
              style="margin-left: 30%; margin-right: 30%"
              :prefix-icon="User"
              type="text"
              v-model="loginForm.username"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
              style="margin-left: 30%; margin-right: 30%"
              :prefix-icon="Lock"
              type="password"
              v-model="loginForm.password"
              show-password
            ></el-input>
          </el-form-item>
          <el-form-item>
            <!-- <el-button
              class="login_btn"
              type="primary"
              plain
              size="default"
              @click="login"
              :loading="loading"
            >
              登 录
            </el-button> -->
            <button
              style="margin-left: 30%; margin-right: 30%; padding: 15px 10px"
              @click="login"
              type="button"
              class="login_newbtn"
            >
              <strong>Go</strong>
              <div id="container-stars">
                <div id="stars"></div>
              </div>

              <div id="glow">
                <div class="circle"></div>
                <div class="circle"></div>
              </div>
            </button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>
<script setup lang="ts">
import { User, Lock } from '@element-plus/icons-vue'
import { ref, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElNotification } from 'element-plus'
//引入获取当前时间的函数
import { getTime } from '@/utils/time'
import useImage from './hooks/useImage'
import feishu from '@/assets/images/mytu/feishu.png'
import { md5 } from 'js-md5'
// import im from '@/assets/images/backgroud1.jfif'
//引入加载
// import load from './loading/index.vue'
// import load from './loading/load1.vue'
// import load from './loading/load2.vue'
//引入用户相关的小仓库
import useUserStore from '@/store/modules/user'
let useStore = useUserStore()
let feishuimg = ref()

feishuimg.value = feishu

let oldUrl = import.meta.env.VITE_AUTH_URL
let newUrl = import.meta.env.VITE_AUTH_URL_HASH
var urlecode =
  newUrl + encodeURIComponent('/#/') + 'auth_login&response_type=code'
let feishuurl = ref(urlecode) //hash模式
// var urlecode =
//   'https://accounts.feishu.cn/accounts/auth_login/oauth2/authorize?client_id=cli_a8adaf1744b85013&redirect_uri=http://localhost:5173/#/auth_login&response_type=code'
// let feishuurl = ref(oldUrl) //history模式
// console.log('图片', feishuimg.value)
//获取el-form组件
let loginForms = ref()

//收集账号与密码的数据
let loginForm = reactive({ username: '', password: '' })
//密码admin 111111
//获取路由器
let $router = useRouter()
//路由对象
let $route = useRoute()
//定义变量控制按钮加载效果
let loading = ref(false)
//背景图
let { currentBackground, changeImage } = useImage()
// let currentBackground1 = im
//登录
const login = async () => {
  //保证全部表单相校验通过再发请求
  await loginForms.value.validate()
  //加载效果:开始加载
  loading.value = true
  //点击登录按钮以后干什么?
  //通知仓库发登录请求
  //请求成功->首页展示数据的地方
  //请求失败->弹出登录失败信息
  //保证登录成功
  // let aa = useStore.userLogin(loginForm)
  // console.log(aa)
  try {
    //保证登录成功,密码加密
    let loginData = {
      username: loginForm.username,
      password: md5(loginForm.password),
    }
    await useStore.userLogin(loginData)

    //编程式导航跳转到展示数据首页
    //判断登录的时候,路由路径当中是否有query参数，如果有就往query参数挑战，没有跳转到首页
    // let redirect: any = $route.query.redirect;
    let redirect: any = $route.query.redirect
    $router.push({ path: redirect || '/' })
    //登录成功提示信息
    ElNotification({
      type: 'success',
      // icon: load,
      message: '欢迎回来',
      title: `HI,${getTime()}好`,
    })
    //登录成功加载效果也消失
    loading.value = false
  } catch (error) {
    console.info(error, ',++++++')
    // console.info(error.message, ',++++++')
    //登录失败加载效果消息
    loading.value = false
    //登录失败的提示信息,error.message捕捉的就是抛出的异常信息,如result.data
    ElNotification({
      type: 'error',
      // icon: load,
      message: (error as Error).message,
      duration: 3000,
    })
  }
}
//自定义校验规则函数
const validatorUserName = (_rule: any, value: any, callback: any) => {
  // console.log(rule)
  //rule:即为校验规则对象
  //value:即为表单元素文本内容
  //函数:如果符合条件callBack放行通过即为
  //如果不符合条件callBack方法,注入错误提示信息
  if (value.length >= 2) {
    callback()
  } else {
    callback(new Error('账号长度至少2位'))
  }
}

const validatorPassword = (_rule: any, value: any, callback: any) => {
  if (value.length >= 6) {
    callback()
  } else {
    callback(new Error('密码长度至少六位'))
  }
}
//定义表单校验需要配置对象
const rules = {
  //规则对象属性:
  //required,代表这个字段务必要校验的
  //min:文本长度至少多少位
  //max:文本长度最多多少位
  //message:错误的提示信息
  //trigger:触发校验表单的时机 change->文本发生变化触发校验,blur:失去焦点的时候触发校验规则
  username: [
    // { required: true, min: 6, max: 10, message: '账号长度至少六位', trigger: 'change' }
    { trigger: 'change', validator: validatorUserName },
  ],
  password: [
    // { required: true, min: 6, max: 15, message: '密码长度至少6位', trigger: 'change' }
    { trigger: 'change', validator: validatorPassword },
  ],
}
</script>
<script lang="ts">
export default {
  name: 'Login',
}
</script>
<style scope lang="scss">
//规则
.el-form-item__error {
  margin-left: 30%;
  margin-right: 30%;
}
//新UI

.drop {
  position: relative;
  width: 450px;
  height: 450px;
  box-shadow: inset 20px 20px 20px rgba(0, 0, 0, 0.05),
    25px 35px 20px rgba(0, 0, 0, 0.05), 25px 30px 30px rgba(0, 0, 0, 0.05),
    inset -20px -20px 25px rgba(255, 255, 255, 0.9);
  transition: 0.5s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 52% 48% 33% 67% / 38% 45% 55% 62%;
}
.btns {
  width: 150px;
  height: 150px;
  // right: -120px;
  bottom: 0;
  background-color: rgb(255 255 255 / 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
  line-height: 1.2em;
  letter-spacing: 0.1em;
  font-size: 0.8em;
  transition: 0.25s;
  text-align: center;
  // box-shadow: inset 10px 10px 10px rgba(190, 1, 254, 0.05),
  //   15px 25px 10px rgba(190, 1, 254, 0.1), 15px 20px 20px rgba(190, 1, 254, 0.1),
  //   inset -10px -10px 15px rgba(255, 255, 255, 0.5);
  border-radius: 44% 56% 65% 35% / 57% 58% 42% 43%;
}

.btns:hover {
  border-radius: 50%;
}

.btns::before {
  content: '';
  position: absolute;
  top: 15px;
  left: 30px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #fff;
  opacity: 0.45;
}

/* From Uiverse.io by StealthWorm */

.clickable-image:hover {
  transform: scale(1.5);
  // box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

.clickable-image:active {
  transform: scale(0.98);
}
@keyframes pulse {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.3);
  }

  100% {
    transform: scale(1);
  }
}

.clickable-image {
  animation: pulse 1s infinite;
  cursor: pointer;
}
.login_newbtn {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 30rem;
  overflow: hidden;
  height: 3rem;
  background-size: 300% 300%;
  cursor: pointer;
  backdrop-filter: blur(1rem);
  border-radius: 5rem;
  transition: 0.5s;
  animation: gradient_301 5s ease infinite;
  border: double 4px transparent;
  background-image: linear-gradient(#212121, #212121),
    linear-gradient(
      137.48deg,
      #ffdb3b 10%,
      #fe53bb 45%,
      #8f51ea 67%,
      #0044ff 87%
    );
  background-origin: border-box;
  background-clip: content-box, border-box;
}

#container-stars {
  position: absolute;
  z-index: -1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  transition: 0.5s;
  backdrop-filter: blur(1rem);
  border-radius: 5rem;
}

strong {
  z-index: 2;
  font-family: 'Avalors Personal Use';
  font-size: 12px;
  letter-spacing: 5px;
  color: #ffffff;
  text-shadow: 0 0 4px white;
}

#glow {
  position: absolute;
  display: flex;
  width: 12rem;
}

.circle {
  width: 100%;
  height: 30px;
  filter: blur(2rem);
  animation: pulse_3011 4s infinite;
  z-index: -1;
}

.circle:nth-of-type(1) {
  background: rgba(254, 83, 186, 0.636);
}

.circle:nth-of-type(2) {
  background: rgba(142, 81, 234, 0.704);
}

.btn:hover #container-stars {
  z-index: 1;
  background-color: #212121;
}

.btn:hover {
  transform: scale(1.1);
}

.btn:active {
  border: double 4px #fe53bb;
  background-origin: border-box;
  background-clip: content-box, border-box;
  animation: none;
}

.btn:active .circle {
  background: #fe53bb;
}

#stars {
  position: relative;
  background: transparent;
  width: 200rem;
  height: 200rem;
}

#stars::after {
  content: '';
  position: absolute;
  top: -10rem;
  left: -100rem;
  width: 100%;
  height: 100%;
  animation: animStarRotate 90s linear infinite;
}

#stars::after {
  background-image: radial-gradient(#ffffff 1px, transparent 1%);
  background-size: 50px 50px;
}

#stars::before {
  content: '';
  position: absolute;
  top: 0;
  left: -50%;
  width: 170%;
  height: 500%;
  animation: animStar 60s linear infinite;
}

#stars::before {
  background-image: radial-gradient(#ffffff 1px, transparent 1%);
  background-size: 50px 50px;
  opacity: 0.5;
}

@keyframes animStar {
  from {
    transform: translateY(0);
  }

  to {
    transform: translateY(-135rem);
  }
}

@keyframes animStarRotate {
  from {
    transform: rotate(360deg);
  }

  to {
    transform: rotate(0);
  }
}

@keyframes gradient_301 {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

@keyframes pulse_3011 {
  0% {
    transform: scale(0.75);
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.7);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 10px rgba(0, 0, 0, 0);
  }

  100% {
    transform: scale(0.75);
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  }
}

.login_container {
  width: 100%;
  height: 100vh; //浏览器高度
  // background: url('@/assets/images/mytu/background1.jpg') no-repeat;
  background-position: center center;
  background-repeat: no-repeat;
  // background-attachment: fixed;
  background-size: cover;
  .login_form:hover {
    border-radius: 50%;
    // height: 550px;
  }
  .login_form::before {
    content: '';
    position: absolute;
    top: 16%;
    left: 15%;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
    opacity: 0.9;
  }
  .login_form::after {
    content: '';
    position: absolute;
    top: 26%;
    left: 20%;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
    opacity: 0.9;
  }
  .login_form {
    transition: 0.5s ease-in-out;
    box-shadow: inset 20px 20px 20px rgba(0, 0, 0, 0.05),
      25px 35px 20px rgba(0, 0, 0, 0.05), 25px 30px 30px rgba(0, 0, 0, 0.05),
      inset -20px -20px 25px rgba(255, 255, 255, 0.9);
    background-color: rgba(255, 255, 255, 0.1);
    // border-radius: 52% 48% 33% 67% / 38% 45% 55% 62%;
    border-radius: 50%;
    position: relative;
    // width: 80%;
    width: 600px;
    height: 600px;
    top: 16vh;
    // background: url('@/assets/images/login_form.png') no-repeat;
    background-size: cover;
    // padding: 40px;
    padding-top: 12%;

    h1 {
      color: white;
      font-size: 40px;
    }

    h2 {
      color: white;
      font-size: 20px;
      margin: 20px 0px;
    }

    .login_btn {
      width: 100%;
      box-shadow: #ecf5ff 0px 7px 0px, #475380 0px 8px 5px;
    }
    .login_btn:hover {
      opacity: 1;
      box-shadow: #6eadec 0px 7px 0px, #475380 0px 8px 5px;
    }

    .login_btn:active {
      top: 4px;
      box-shadow: #409eff 0px 3px 0px, #475380 0px 3px 5px;
    }
  }
}
</style>
